package com.wlcj.plugin;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.jfinal.plugin.IPlugin;
import com.wlcj.util.SpringUtil;

public class SpringIocPlugin implements IPlugin {

	private String[] configurations;
	private ApplicationContext ctx;
	
	/**
	 * Use configuration under the path of WebRoot/WEB-INF.
	 */
	public SpringIocPlugin() {
	}
	
	public SpringIocPlugin(String... configurations) {
		this.configurations = configurations;
	}
	
	public SpringIocPlugin(ApplicationContext ctx) {
		this.ctx = ctx;
	}
	
	public boolean start() {
		if (ctx != null)
			SpringUtil.ctx = ctx;
		else if (configurations != null)
			SpringUtil.ctx = new ClassPathXmlApplicationContext(configurations);
		else
			SpringUtil.ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		return true;
	}
	
	public boolean stop() {
		return true;
	}

}
